
* Replication code for analysis in online appendix

* Article: 	"Local conflict intensity and public perceptions of the police: Evidence from Afghanistan"
* Journal: 	Journal of Politics 
* Authors:	Annekatrin Deglow & Ralph Sundberg
* Contact: 	annekatrin.deglow@pcr.uu.se
* Do file: 	oa_analysis_ADRS.do
* Dataset:	analysis_ADRS.dta

// NOTE: The analyses are listed in line with the online appendix' list of content.
// Analyses that require a different data set are listed at the end of the dofile 
// (Table 3, Table 14, and Table 17,).
*-------------------------------------------------------------------------------
clear
version 15 
set more off
// set your working directory here
// use "analysis_ADSR.dta"
// log using oa_analysis_ADRS

*-------------------------------------------------------------------------------
* Descriptive statistics (Table A2)
*-------------------------------------------------------------------------------
sum x36e_dummy x36a_dummy x34b_dummy x36e_ord x36e_ord x36e_ord abosv_sum ///
abosv_sumtwoyear age gender_dummy pashtun_dummy rur_urb_dummy ///
radio_dummy education income ANP_corrupt opium_adm2 adm2_ethn log_dist_pop ///
year_int_cat


* Note: Replace with proportion per category for variables with more than two categories
tab income
tab education
tab ANP_corrupt
tab year_int_cat


*-------------------------------------------------------------------------------
* Regressing effectiveness and proc. justice on trust in the police (Table A4)
*-------------------------------------------------------------------------------

* Binary regression (M1)
melogit x34b_dummy x36e_dummy x36a_dummy  i.year_int_cat || adm_2_num:

* Regression with individual and district-level controls (M2)
melogit x34b_dummy x36e_dummy x36a_dummy abosv_sum abosv_sumtwoyear ///
		age gender_dummy i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
        opium_adm2 adm2_ethn log_dist_pop ///
		i.year_int_cat || adm_2_num:

*-------------------------------------------------------------------------------
* Regression results for categorical variables (Table A5)
*-------------------------------------------------------------------------------
// See code in section "Table 1: Effect of conflict intensity on perceptions of police " 
// in "main_analysis_ADRS.do" 


*-------------------------------------------------------------------------------
* Analysis of female subsample (Table A6)
*-------------------------------------------------------------------------------

foreach y in x36e_dummy x36a_dummy x34b_dummy {  

	// Run the main models (M3, M6, M9) on female subsample
	melogit `y' abosv_sum  abosv_sumtwoyear ///
	age  i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
    opium_adm2 adm2_ethn log_dist_pop ///
	i.year_int_cat if gender_dummy==0|| adm_2_num:
	
	// Run the main models (M3, M6, M9) on male subsample 
	melogit `y' abosv_sum  abosv_sumtwoyear ///
	age  i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
    opium_adm2 adm2_ethn log_dist_pop ///
	i.year_int_cat if gender_dummy==1|| adm_2_num:
}

*-------------------------------------------------------------------------------
* Independent variable: all forms of organized violence (Table A7)
*-------------------------------------------------------------------------------
foreach y in x36e_dummy x36a_dummy x34b_dummy {  

	// Run the main models (M3, M6, M9) 
	melogit `y' best_est_sum  best_est_sumtwoyear ///
	age gender_dummy i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
    opium_adm2 adm2_ethn log_dist_pop ///
	i.year_int_cat || adm_2_num:
}

*-------------------------------------------------------------------------------
* Independent variable: Excluding one-sided violence by non-state actors (Table A8)
*-------------------------------------------------------------------------------
foreach y in x36e_dummy x36a_dummy x34b_dummy {  

	// Run the main models (M3, M6, M9) 
	melogit `y' ab_sum  ab_sumtwoyear ///
	ns_osv_sum age gender_dummy i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
    opium_adm2 adm2_ethn log_dist_pop ///
	i.year_int_cat || adm_2_num:
}

*-------------------------------------------------------------------------------
* Independent variable: log-transformed (Table A9)
*-------------------------------------------------------------------------------

foreach y in x36e_dummy x36a_dummy x34b_dummy {  

	// Run the main models (M3, M6, M9) 
	melogit `y' abosv_sumlog abosv_sumtwoyearlog ///
	age gender_dummy i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
    opium_adm2 adm2_ethn log_dist_pop ///
	i.year_int_cat || adm_2_num:
}

*-------------------------------------------------------------------------------
*  Independent variable: Changing temporal vicinity (Table A10)
*-------------------------------------------------------------------------------

foreach y in x36e_dummy x36a_dummy x34b_dummy {  

	// Run the main models (M3, M6, M9) 
	melogit `y' abosv_03m abosv_36m abosv_69m abosv_912m abosv_sumtwoyear ///
	age gender_dummy i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
    opium_adm2 adm2_ethn log_dist_pop  ///
	i.year_int_cat || adm_2_num:
}


*-------------------------------------------------------------------------------
*  Independent variable: Ordered multilevel logistic regression (Table A11)
*-------------------------------------------------------------------------------

foreach y in x36e_ord x36a_ord x34b_ord{  

	// Run the main models (M3, M6, M9) 
	meologit `y' abosv_sum  abosv_sumtwoyear ///
	age gender_dummy i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
    opium_adm2 adm2_ethn log_dist_pop  ///
	i.year_int_cat || adm_2_num:
}

*-------------------------------------------------------------------------------
*  Fixed-effects logistic regression (Table A12)
*-------------------------------------------------------------------------------
// Note: Conditional fixed effects models; require Kabul City district to be ommitted
// and do not include district-invariant controls (population size)
// [computing takes long]
 
foreach y in x36e_dummy x36a_dummy x34b_dummy {  

	// Run the main models (M3, M6, M9) 
	clogit `y' abosv_sum  abosv_sumtwoyear ///
	age gender_dummy i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
    opium_adm2 adm2_ethn ///
	i.year_int_cat if adm_2_num!=1, group(adm_2_num)
}

*-------------------------------------------------------------------------------
*  Accounting for omitted variable bias (Table A13)
*-------------------------------------------------------------------------------
// See section "Altonji rates" on "main_analysis_ADRS.do"


*-------------------------------------------------------------------------------
* Testing preference falsification (Table A15)
*-------------------------------------------------------------------------------

foreach y in x36e_dummy x36a_dummy x34b_dummy x36e_ord x36a_ord x34b_ord {  

	// mean of binary and ordinal  outcome variables by ethnicity 
	// (pashtun=1, other=0)
	sum `y' if pashtun==0
	sum `y' if pashtun==1
}


*-------------------------------------------------------------------------------
* Tests for alternative explanations
*-------------------------------------------------------------------------------
* (1) Government and ISAF Perceptions (Table 16 and 17)

// Controlling in addition for central and local government perception (Table 16)
foreach y in x36e_dummy x36a_dummy x34b_dummy {
	
	// Run the main models (M3, M6, M9) 
	melogit `y' abosv_sum  abosv_sumtwoyear ///
	i.gvt_percept_ord i.pgvt_percept_ord ///
	age gender_dummy i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
    opium_adm2 adm2_ethn log_dist_pop  ///
	i.year_int_cat  || adm_2_num:
}


* (2) Civilian Loyalties (Table 18)
foreach y in x36e_dummy x36a_dummy x34b_dummy {  

	// Run the main models (M3, M6, M9) on pro-government subsample
	melogit `y' abosv_sum  abosv_sumtwoyear ///
	age pashtun_dummy gender_dummy i.education i.income radio_dummy rur_urb_dummy i.ANP_corrupt  ///
    opium_adm2 adm2_ethn log_dist_pop ///
	i.year_int_cat if gvt_percept_dummy==1  || adm_2_num:

	// Run the main models (M3, M6, M9) on anti-government subsample
	melogit `y' abosv_sum  abosv_sumtwoyear ///
	age pashtun_dummy gender_dummy i.education i.income radio_dummy rur_urb_dummy i.ANP_corrupt  ///
    opium_adm2 adm2_ethn log_dist_pop ///
	i.year_int_cat if gvt_percept_dummy==0  || adm_2_num:	
}


* (3) Crime and Conflict Intensity (Table 19)
melogit crime abosv_sumtwoyear ///
        age  gender i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
		opium_adm2 adm2_ethn log_dist_pop ///
		i.year_int_cat || adm_2_num: 

		
*-------------------------------------------------------------------------------
* Factor analysis (Table A3)
*-------------------------------------------------------------------------------
// Note: Requires different dataset (all observations for 2007-2012 that have 
// answers on all items on policing used in the FA)
// use "oa_analysis_fa_ADRS.dta"
clear
version 15 
set more off
// use "oa_analysis_fa_ADRS.dta"

factor  x34b_ord x36e_ord x36a_ord x36b_ord x36c_ord x36d_ord x21_ord 
rotate

*-------------------------------------------------------------------------------
* Testing preference falsification (Table A14)
*-------------------------------------------------------------------------------
// Note: Requires different dataset (including all observations with and without 
// missing values on original ordinal outcome items between 2007-2012)
// use "oa_analysis_pf_ADRS.dta"
clear
version 15 
set more off
// use "oa_analysis_pf_ADRS.dta"

// Percentiles for conflict intensity
sum abosv_sum, det

// N in top 5 conflict affected districts: 1,867
sum abosv_sum if abosv_sum > 93 

// N in non-affected districts: 13,308
sum abosv_sum if abosv_sum == 0 

foreach y in x36e_ord x36a_ord x34b_ord{  
	
	// Generate variable with count and percentage of item non response for all 
	///three outcomes by conflict intensity (individuals top 5% vs not affected)
	misschk `y' if abosv_sum > 93, gen(inrtop5_`y')
	misschk `y' if abosv_sum == 0, gen(inr0_`y') 	
}

*-------------------------------------------------------------------------------
* Tests for alternative explanations (Table A17)
*-------------------------------------------------------------------------------
// Controlling in addition for central, local government and isaf perception (Table 17)
// Note: Requires different dataset (subsample for the years 2011-2012)
// use "oa_analysis_isaf_ADRS.dta" 
clear
version 15 
set more off
// use "oa_analysis_isaf_ADRS.dta"

foreach y in x36e_dummy x36a_dummy x34b_dummy {
	
	// Run the main models (M3, M6, M9) 
	melogit `y' abosv_sum  abosv_sumtwoyear ///
	i.isaf_percept_ord i.gvt_percept_ord i.pgvt_percept_ord ///
	age gender_dummy i.education i.income pashtun_dummy radio_dummy rur_urb_dummy i.ANP_corrupt ///
    opium_adm2 adm2_ethn log_dist_pop  ///
	i.year_int_cat  || adm_2_num: 
}

*-------------------------------------------------------------------------------
//log close
